﻿using KillBill.Business.Entities;
using KillBill.Business.Modules.Sales;
using KillBill.Services.Modules.Sales.IServices;
using KillBill.Services.DTO;
using KillBill.Services.Modules.Sales.SecurityServiceReference;

namespace KillBill.Services.Modules.Sales
{
    public class SalesService : ISalesService
    {
        private SalesManager _salesManager;
        private SecurityServiceClient _securityService;

        public SalesService()
        {
            _salesManager = new SalesManager();
            _securityService = new SecurityServiceClient();
        }

        public SalesHeader RegisterSale(SalesHeader salesHeader, string sessionId)
        {
            KillBillDTO sessionDTO = _securityService.IsAuthorized(sessionId, new string[] { "Administrador", "Cajero" });
            var outDTO = new SalesHeader();
            if (!sessionDTO.Success)
            {
                outDTO.Success = false;
                outDTO.Messages = sessionDTO.Messages;
            }
            else
                outDTO = _salesManager.RegisterSale(salesHeader);
            return outDTO;
        }
    }

}
